package com.hanbang.taitaigou.ui.activity.login;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebSettings.LayoutAlgorithm;

import com.hanbang.taitaigou.R;
import com.hanbang.taitaigou.ui.activity.base.BaseActivity;
import com.hanbang.taitaigou.utils.http.HttpInterfaces;
import com.hanbang.taitaigou.utils.ui.LogUtils;


public class RegisterProtocolActivity extends BaseActivity {

	private WebView webview = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.register_protocol);
		initView();
		setOnClickListener();
		zhuCeXieYi();

	}

	private void zhuCeXieYi() {
		webview.loadUrl("http://cqqjk.hbung.com/zhucexieyiapp.html");
	}

	/*
	 * 设置点击事件
	 */
	private void setOnClickListener() {

	}

	/*
	 * 初始化view
	 */
	private void initView() {
		// 设置顶部的标题
		setBackArrows(findViewById(R.id.top_bar_left));
		setTop(null, R.mipmap.back, "注册协议", null, 0);

		webview = (WebView) findViewById(R.id.webview);
		configWebview();

	}

	/*
	 * http://localhost:10080/tools/UserLogin.ashx?action=registration_agreement
	 * --注册协议
	 */
	private void getProtocol() {
	}

	@SuppressLint("SetJavaScriptEnabled")
	private void configWebview() {
		// 设置文本编码
		webview.getSettings().setDefaultTextEncodingName("utf-8");
		// 可以缩放
		webview.getSettings().setSupportZoom(true);
		webview.getSettings().setJavaScriptEnabled(true);
		webview.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
		webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
		// 开启 Application Caches 功能
		webview.getSettings().setAppCacheEnabled(false);
		webview.getSettings().setLoadWithOverviewMode(true);
		// webView.getSettings().setDefaultZoom(ZoomDensity.MEDIUM);// 默认缩放模式
		webview.getSettings().setUseWideViewPort(false);
	}

	/*
	 * 获取到服务器数据后开始跟新UI
	 */
	private void upDateUI(String content) {
		// 配置webview数据源
		StringBuilder data = new StringBuilder();
		data.append("<style type=\"text/css\">img{WIDTH:80% !important;HEIGHT:auto !important;}");
		data.append(getFont());
		data.append("</style><base href=\"");
		data.append(HttpInterfaces.ORG);
		data.append("\"/><body class=\"Likun\" style=\"padding-left:2%;padding-right:2%;\">");
		data.append(content);
		data.append("</body>");
		LogUtils.e("upDateUI", data.toString());

		// 设置webview 加载数据
		webview.loadDataWithBaseURL(null, data.toString(), "text/html",
				"utf-8", null);
	}

	private String getFont() {
		StringBuilder builder = new StringBuilder();
		// <body class="MsoNormal"> </body>
		builder.append(".Likun { font-family: fzlt;}");
		builder.append("@font-face {font-family:fzlt;");
		builder.append("src:url(file:///android_asset/fzlt.ttf);}");
		return builder.toString();
	}

	@Override
	protected void onResume() {
		super.onResume();
	}

	@Override
	protected void onPause() {
		super.onPause();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}
}
